import { defineStore } from 'pinia';
import { getDicts } from '@/api/public';


export default defineStore('dict', {
	state: () => state,
	actions: {
		// 字典接口
		getDictsFn(data) {
			return new Promise((resolve, reject) => {
				const key = camelCase(data)

				if(this[key] === undefined) this[key]=[]

				if (this[key].length > 0) {
					resolve(state[key]);
				} else {
					getDicts(data)
						.then((res) => {
							this[key] = res.data;
							resolve(this[key]);
						})
						.catch((err) => {
							reject(err);
						});
				}
			});
		}
	}
});
